package reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
        Person p=new Person();
        p.doSome();


        Class cls=Class.forName("reflect.Person");
        Object obj=cls.getName();
        Method method=cls.getMethod("doSome");
        method.invoke(obj);

        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入类名：");
        String className=scanner.nextLine();
        System.out.println("请输入方法名：");
        String methodName=scanner.nextLine();
        Class cls1=Class.forName(className);
        Object obj1=cls1.newInstance();
        Method method1=cls1.getMethod(methodName);
        method1.invoke(obj1);
    }
}
